package com.lock;

import com.lock.agency.MyOrderLockInvocationHandler;
import com.lock.common.FBSOrderLock;
import com.lock.proxied.UserInterface;
import com.lock.proxied.UserServer;

import java.lang.reflect.Proxy;
import java.util.concurrent.CountDownLatch;

/**
 * 基于动态代理的有序临时节点分布式锁实现
 * 其中支持单例或多例的模式
 * 注解形式的详见baseTest
 * Created by hx on 2017/7/17.
 */
public class main {
    public static void main(String[] args) throws InterruptedException {
        //保证主线程等待所有线程执行完才执行
        final CountDownLatch countDownLatch = new CountDownLatch(10);
        final UserInterface userServer = new UserServer();
        for (int i=0;i<10;i++) {
            new Thread(new Runnable() {
                public void run() {
                    MyOrderLockInvocationHandler myOrderLockInvocationHandler = new MyOrderLockInvocationHandler(userServer);
                    UserInterface proxy = (UserInterface) myOrderLockInvocationHandler.getProxy();
                    proxy.add();
                    countDownLatch.countDown();
                }
            }).start();
        }
        countDownLatch.await();
    }
}
